package com.wjh.web;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wjh.base.ResponseApiData;
import com.wjh.goods.entity.GoodsEntity;
import com.wjh.service.IGoodsService;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

/**
 * 商品对外 API接口
 * 
 * @author wenjianhai
 * @date 2023/6/26
 * @since JDK 17
 */
@Tag(name = "商品对外 AIP接口", description = "商品对外 AIP接口")
@Slf4j
@RestController
@RequestMapping("/goods/api")
public class GoodsApiController {

	@Autowired
	private IGoodsService goodsService;

	@GetMapping("/queryByGuid/{goodsGuid}")
	public ResponseApiData<GoodsEntity> queryByGuid(@PathVariable String goodsGuid) {
		log.info("根据商品Guid查询商品详情-开始.商品Guid:{}", goodsGuid);
		if (StringUtils.isBlank(goodsGuid)) {
			return ResponseApiData.parameterFail("商品Guid不能为空");
		}
		try {
			return ResponseApiData.success(goodsService.queryByGuid(goodsGuid));
		} catch (Exception e) {
			log.error(String.format("根据商品Guid查询商品详情-失败.商品Guid:%s", goodsGuid), e);
			return ResponseApiData.systemFail(e.getMessage());
		}
	}
}
